<div class="layuimini-main">

    <div class="layui-form layuimini-form">
        <div class="layui-form-item">
            <label class="layui-form-label required">ID</label>
            <div class="layui-input-block">
                <input type="text" name="id"  value={{.id}} class="layui-input" readonly>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label required">用户名</label>
            <div class="layui-input-block">
                <input type="text" name="username"  value={{.useranme}} class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">邮箱</label>
            <div class="layui-input-block">
                <input type="email" name="email"  value={{.email}} class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">剩余下载次数</label>
            <div class="layui-input-block">
                <input name="remaining"   value={{.remaining}} class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">账户密码</label>
            <div class="layui-input-block">
                <input name="password"   value={{.password}} class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">账户状态</label>
            <div class="layui-input-block">
                {{if eq .status "启用"}}
                <input type="checkbox" name="checkbox"  lay-skin="switch"  lay-filter="switch" lay-text="启用|禁用" checked>
                {{else}}
                <input type="checkbox" name="checkbox"  lay-skin="switch"  lay-filter="switch"  lay-text="启用|禁用">
                {{end}}
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
            </div>
        </div>
    </div>
</div>
<script>
    layui.use(['form', 'table'], function () {
        var form = layui.form,
            layer = layui.layer,
            table = layui.table,
            $ = layui.$;

        /**
         * 初始化表单，要加上，不然刷新部分组件可能会不加载
         */
        form.render();

        // 当前弹出层，防止ID被覆盖
        var parentIndex = layer.index;

        //监听提交
        form.on('submit(saveBtn)', function (data) {
            var index = layer.alert('确定修改', {
                title: '信息'
            }, function () {
                var restful=JSON.stringify(data.field)
                $.post(
                            "/admin/users/api/update",
                            "restful="+restful,
                            function (res) {
                                if (res.status) {
                                    layer.msg(res.message, { time: 2000 });
                                } else {
                                    layer.msg(res.message, { time: 2000 });
                                }
                            }, 'json');

                // 关闭弹出层
                layer.close(index);
                layer.close(parentIndex);

            });


            return false;
        });

        //监听指定开关
        form.on('switch(switch)', function(data){
            layer.msg('账户'+ (this.checked ? '启用' : '禁用'), {
                offset: '6px'
            });
        });

    });
</script>